package ch.bfh.abcm.rems.sensors.tinkerforge;

public class TFSensorConfigDefinition {

    public static final int DEFAULT_CALL_BACK_PERIOD = 500;
    public static final String DEFAULT_HOST_UID = "unknown";

    private static final int DEFAULT_PORT = TFSensorController.DEFAULT_PORT;

    private TFSensorType sensorType;
    private String uid;
    private String host;
    private String hostUID;
    private long callBackPeriod;
    private int port;

    public TFSensorConfigDefinition(TFSensorType sensorType, String uid, String host) {
        this(sensorType, uid, host, DEFAULT_HOST_UID, DEFAULT_CALL_BACK_PERIOD, DEFAULT_PORT);
    }
    
    public TFSensorConfigDefinition(TFSensorType sensorType, String uid, String host, String hostUID) {
        this(sensorType, uid, host, hostUID,  DEFAULT_CALL_BACK_PERIOD, DEFAULT_PORT);
    }

    public TFSensorConfigDefinition(TFSensorType sensorType, String uid, String host, long callBackPeriod) {
        this(sensorType, uid, host, DEFAULT_HOST_UID, callBackPeriod, DEFAULT_PORT);
    }
    
    public TFSensorConfigDefinition(TFSensorType sensorType, String uid, String host, String hostUID, long callBackPeriod) {
        this(sensorType, uid, host, hostUID, callBackPeriod, DEFAULT_PORT);
    }

    public TFSensorConfigDefinition(TFSensorType sensorType, String uid, String host, String hostUID, long callBackPeriod, int port) {
        this.sensorType = sensorType;
        this.uid = uid;
        this.host = host;
        this.callBackPeriod = callBackPeriod;
        this.port = port;
        this.hostUID = hostUID;
    }

    public static int getDefaultPort() {
        return DEFAULT_PORT;
    }

    public static int getDefaultCallBackPeriod() {
        return DEFAULT_CALL_BACK_PERIOD;
    }

    public TFSensorType getSensorType() {
        return sensorType;
    }

    public String getUid() {
        return uid;
    }

    public String getHost() {
        return host;
    }

    public long getCallBackPeriod() {
        return callBackPeriod;
    }

    public int getPort() {
        return port;
    }

    public String getHostUID() {
        return hostUID;
    }

    @Override
    public String toString() {
        return "TFSensorConfig{sensorType=" + sensorType + " uid=" + uid + " host=" + host + " hostUID=" + hostUID
                + "}";
    }
    
    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true; // same memory Reference
        }
        if (other == null) {
            return false; // null is never equals
        }
        if (other.getClass() != getClass()) {
            return false; // Not the same Class
        }
        // check fields
        boolean sameUID = uid.equals(((TFSensorConfigDefinition)other).getUid());
        boolean sameSensorType= sensorType.equals(((TFSensorConfigDefinition)other).getSensorType());
        boolean sameHost = host.equals(((TFSensorConfigDefinition)other).getHost());
        boolean sameHostUID = hostUID.equals(((TFSensorConfigDefinition)other).getHostUID());
        boolean sameCBP = callBackPeriod == (((TFSensorConfigDefinition)other).getCallBackPeriod());
        if (sameUID && sameSensorType && sameHost && sameHostUID && sameCBP) {
            return true;
        }
        // every other szenario...
        return false;
    }
    
    
}
